package com.ruslan.magaz.domain;
// default package
// Generated 28.09.2014 13:25:18 by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * Category generated by hbm2java
 */
@Entity
@Table(name = "category", catalog = "eshop")
public class Category implements java.io.Serializable {

	private int categoryId;
	@Size(min=2,max=20,message=	"name must be between 2 and 20 characters long.")
	@Pattern(regexp="(?U)^(\\w)*$",	message="Illegal format")
	private String name;
	private Integer parentCategory;
	private Set<Product> products = new HashSet<Product>(0);

	public Category() {
	}

	public Category(int categoryId) {
		this.categoryId = categoryId;
	}

	public Category(int categoryId, String name, Integer parentCategory,
			Set<Product> products) {
		this.categoryId = categoryId;
		this.name = name;
		this.parentCategory = parentCategory;
		this.products = products;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "Category_id", unique = true, nullable = false)
	public int getCategoryId() {
		return this.categoryId;
	}

	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}

	@Column(name = "Name", length = 100)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "ParentCategory")
	public Integer getParentCategory() {
		return this.parentCategory;
	}

	public void setParentCategory(Integer parentCategory) {
		this.parentCategory = parentCategory;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "category")
	public Set<Product> getProducts() {
		return this.products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}

}
